//
//  HQHSecondListViewController.m
//  LastOne
//
//  Created by 小柠檬 on 15/11/4.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "HQHSecondListViewController.h"
#import "HQHListDetailCollectionViewCell.h"
#import "HQHHotListDetailCollectionViewCell.h"
#import "HQHListDetailWebViewController.h"
#import "FitHeader.h"
#import "NightHeader.h"
@interface HQHSecondListViewController ()
@end

@implementation HQHSecondListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    UIBarButtonItem *newButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"HQHNewImage"] style:UIBarButtonItemStylePlain target:self action:@selector(newButtonAction)];
    
    UIBarButtonItem *hotButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"HQHHotImage"] style:UIBarButtonItemStylePlain target:self action:@selector(hotButtonAction)];
    
    NSArray *array = [NSArray arrayWithObjects:hotButton, newButton, nil];
    self.navigationItem.rightBarButtonItems = array;
    
//    NSLog(@"%ld", (long)[_type integerValue]);
    
}

-(void)loadView
{
    [super loadView];

#pragma mark collectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(375 * FitWidth, 574 * FitHeight);
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.pageCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 375 * FitWidth, 574 * FitHeight) collectionViewLayout:flowLayout];
    _pageCollectionView.delegate = self;
    _pageCollectionView.dataSource = self;
    _pageCollectionView.backgroundColor = [UIColor whiteColor];
    [_pageCollectionView NightWithType:UIViewColorTypeNormal];
    

    _pageCollectionView.pagingEnabled = YES;
    [self.view addSubview:_pageCollectionView];
    
    [_pageCollectionView registerClass:[HQHListDetailCollectionViewCell class] forCellWithReuseIdentifier:@"identifier"];
    
    [_pageCollectionView registerClass:[HQHHotListDetailCollectionViewCell class] forCellWithReuseIdentifier:@"identifier2"];
    

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 2;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        HQHListDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifier" forIndexPath:indexPath];
        cell.type = _type;
        cell.myNewDelegate = self;
        return cell;
    }
    else if (indexPath.row == 1)
    {
        HQHHotListDetailCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"identifier2" forIndexPath:indexPath];
        cell.type = _type;
        cell.myHotDelegate = self;
        return cell;
    }
    
    return nil;
}

-(void)newButtonAction
{
    _pageCollectionView.contentOffset = CGPointMake(0, 0);
}

-(void)hotButtonAction
{
    _pageCollectionView.contentOffset = CGPointMake(375 * FitWidth, 0);
}

-(void)passNewValue:(HQHListDetailModel *)listDetailModel With:(NSString *)ID
{
    HQHListDetailWebViewController *listWebVC = [[HQHListDetailWebViewController alloc]init];
    listWebVC.ID = ID;
    listWebVC.model = listDetailModel;
    [self.navigationController pushViewController:listWebVC animated:YES];
}

-(void)passHotValue:(HQHListDetailModel *)listDetailModel With:(NSString *)ID
{
    HQHListDetailWebViewController *listWebVC = [[HQHListDetailWebViewController alloc]init];
    listWebVC.ID = ID;
    listWebVC.model = listDetailModel;
    [self.navigationController pushViewController:listWebVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
